<!-- Copyright 2013 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -->
<!DOCTYPE html>
<title>Unit Test of e2e.signer.Ecdsa</title>
<script src="../../../closure/base.js"></script>
<script src="test_js_deps-runfiles.js"></script>
<script>
  goog.require('e2e.BigNum');
  goog.require('e2e.ecc.PrimeCurve');
  goog.require('e2e.ecc.Protocol')
  goog.require('e2e.random');
  goog.require('e2e.signer.Algorithm');
  goog.require('e2e.signer.Ecdsa');
  goog.require('goog.testing.jsunit');
</script>
<script>
/**
 * Tests that ECDSA is consistent.
 */
function testConsistency() {
  for (var i = 0; i < 5; i++) {
    var ecdsa = new e2e.signer.Ecdsa(
        e2e.signer.Algorithm.ECDSA,
        e2e.ecc.Protocol.generateKeyPair(e2e.ecc.PrimeCurve.P_256));
    var m = e2e.random.getRandomBytes(20);
    var sig = e2e.async.Result.getValue(ecdsa.sign(m));

    assertTrue(e2e.async.Result.getValue(ecdsa.verify(m,sig)));
    assertFalse(e2e.async.Result.getValue(ecdsa.verify(
      e2e.random.getRandomBytes(20), sig)));
  }
}
</script>
